package day20200928_两数之和;

import org.junit.Test;

import java.util.HashMap;
import java.util.Map;

/*
*   两数之和
* https://leetcode-cn.com/problems/two-sum/solution/liang-shu-zhi-he-by-leetcode-2/
*/

public class day20200928 {
    public int[] test(int[] nums, int target) {
        int[] list = new int[2];
        for (int i = 0 ; i < nums.length-1 ; i++) {
            for (int j = i+1 ; j < nums.length ; j++ ) {
                if (nums[i] + nums[j] == target) {
                    list[0] = nums[i];
                    list[1] = nums[j];
                    return list;
                }
            }
        }
//        如果运行到此处，说明没有正确结果，可以直接抛出异常，
        return null;
    }

    @Test
    public void test01() {
        int[] a = {2, 7, 11, 15};
        int[] l = test(a,9);
        if (l == null) {
            System.out.println("no");
        }else {
            for (int i : l) {
                System.out.println(i);
            }
        }
    }

    @Test
    public void test02() {
        Map<Integer,Integer> map = new HashMap<>();

    }
}
